package com.neusoft.neu24.nep.role.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.neu24.nep.entity.ComonResult;
import com.neusoft.neu24.nep.entity.Member;
import com.neusoft.neu24.nep.role.mapper.MemberMapper;
import com.neusoft.neu24.nep.role.myjwt.JwtService;
import com.neusoft.neu24.nep.role.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl  extends ServiceImpl<MemberMapper, Member> implements IMemberService {

    @Autowired
    JwtService jwtService;
    @Override
    public ComonResult<Member> login(String logid, String logpwd) {

        LambdaQueryWrapper<Member> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Member::getLogid,logid);
        queryWrapper.eq(Member::getLogpwd,logpwd);
        Member member = getOne(queryWrapper);
        if(member != null){
            member.setToken(jwtService.generateToken(member));
            return ComonResult.success(member);
        }


        return null;
    }

    @Override
    public ComonResult<Member> pass(String token) {
        Member member =  jwtService.parseToken(token);
        if (member!=null){
            return ComonResult.success(member);
        }
        return null;
    }
}
